﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    using DAL.Entities;

    public class DienKeDAL : BaseDAL, UTL.IBaseDAL
    {
        public int Count()
        {
            throw new NotImplementedException();
        }

        public DataTable Select()
        {
            string sql = @" SELECT * from dienke ";
            return ExecuteQuery(sql);
        }

        public DataTable Select(object obj)
        {
            throw new NotImplementedException();
        }

        public object GetByKey(object key)
        {
            throw new NotImplementedException();
        }

        public bool Delete(string id)
        {
            string sql = @" DELETE FROM dienke WHERE ma_dk = '{0}' ";
            sql = string.Format(sql,id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Insert(object obj)
        {
            var o = (Dien_Ke)obj;
            string sql = @"INSERT INTO dienke(ma_dk,diengiai,ma_hd) VALUES('{0}',N'{1}','{2}')";
            sql = string.Format(sql,o.ma_dk,o.diengiai,o.ma_hd);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            var o = (Dien_Ke)obj;
            string sql = @"UPDATE dienke SET diengiai=N'{0}', ma_hd='{1}' WHERE ma_dk='{2}' ";
            sql = string.Format(sql,o.diengiai,o.ma_hd,o.ma_dk);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public DataTable Search(string name)
        {
            throw new NotImplementedException();
        }

        public DataTable Select_hopdong()
        {
            string sql = @" SELECT ma_hd as id FROM hopdongdien ";
            return ExecuteQuery(sql);
        }
    }
}
